﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Configuration;

namespace devtm.Editor.Configuration.Command
{
    
    public class NameValueCollectionCommand : ICommand
    {
        

        
        private IElementSection elementSection;
        //private System.Configuration.ConfigurationElement configurationElement;
        private System.Collections.Specialized.NameValueCollection List;
        private string OldValue;
        private string NewValue;
        private string Key;

        private TypeChange Change;
        public NameValueCollectionCommand(IElementSection elementSection, System.Collections.Specialized.NameValueCollection list, string key, string oldValue, string newValue, TypeChange change)
        {

            Change = change;
            this.elementSection = elementSection;
            Key = key;
            List = list;
            OldValue = oldValue;
            NewValue = newValue;

        }

        public void Undo()
        {

            switch (Change)
            {
                case TypeChange.Add:
                    List.Remove(Key);
                    break;
                case TypeChange.Remove:
                    List.Add(Key, NewValue);
                    break;
                case TypeChange.Change:
                    List[Key] = OldValue;
                    break;
                default:
                    break;
            }

        }

        public void Redo()
        {
            switch (Change)
            {
                case TypeChange.Add:
                    List.Add(Key, NewValue);
                    break;
                case TypeChange.Remove:
                    List.Remove(Key);
                    break;
                case TypeChange.Change:
                    List[Key] = NewValue;
                    break;
                default:
                    break;
            }
        }

    }
}
